package com.three.crm.page.setting;


import android.content.Context;
import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.widget.TextView;

import com.lxj.xpopup.XPopup;
import com.lxj.xpopup.core.BasePopupView;
import com.three.crm.R;
import com.three.crm.base.BaseActivity;
import com.three.crm.constant.AppConstant;
import com.three.crm.http.CommonResultCallBack;
import com.three.crm.require.AppRequireService;
import com.three.crm.util.AppManager;
import com.three.crm.util.SignUtil;
import com.three.crm.util.TString;

import org.json.JSONException;
import org.json.JSONObject;

import okhttp3.Call;

/**
 * 关于我们
 * created by lqd 2024-01-04.
 */
public class AboutUsActivity extends BaseActivity {

    private int id = 33;
    private TextView tvTitle,tvContent;

    @Override
    protected void initParms(Bundle bundle) {}

    @Override
    protected int bindLayout() {
        return R.layout.activity_about_us;
    }

    @Override
    protected void initViews(View view, Bundle savedInstanceState) {
        tvTitle = $(R.id.tv_title);
        tvTitle.setText(R.string.about_us);
        tvContent = $(R.id.tv_content);
    }

    @Override
    protected void setListener() {
        $(R.id.iv_left).setOnClickListener(this);
    }

    @Override
    protected void widgetClick(View v) {
        switch (v.getId()){
            case R.id.iv_left:
                finish();
                break;
        }
    }

    @Override
    protected void initData(Context mContext) {
        queryDetail();
    }

    private void queryDetail() {
        if (id != 0) {
            showLoading(getString(R.string.loading));
            JSONObject jsonObject = new JSONObject();
            try {
                jsonObject.put("userToken", AppManager.getToken());
                jsonObject.put("id",id);
                jsonObject.put("timestamp",getTimestamp());
                String sign = SignUtil.genSign(jsonObject);
                jsonObject.put("sign",sign);
                AppRequireService.queryArticle(this, AppConstant.QUERY_DETAIL, jsonObject, new CommonResultCallBack(this) {
                    @Override
                    public void onResult(String result, int requireCode) {
                        hideLoading();
                        if (requireCode == AppConstant.QUERY_DETAIL) {
                            if (!TString.isEmpty(result)) {
                                try {
                                    JSONObject object = new JSONObject(result);
                                    setDetail(object);
                                } catch (JSONException e) {
                                    e.printStackTrace();
                                }
                            }
                        }
                    }

                    @Override
                    public void onConnectTimeOut(Call call, Exception e, int requireCode) {
                        hideLoading();
                        showToast(e.getMessage());
                    }

                    @Override
                    public void onFail(String msg, int requireCode) {
                        hideLoading();
                        showToast(msg);
                    }
                });
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }

    private void setDetail(JSONObject object) {
        if (object != null) {
            try {
                String content = object.getString("content");
                tvContent.setText(Html.fromHtml(content));
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }
}